<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\dynamic\model;

class DynamicList extends \app\BaseModel
{
    protected $name = "massage_dynamic_list";
    protected $append = ["friend_time"];
    public function getFriendTimeAttr($value, $data)
    {
        if(isset($data["create_time"])) {
            return lbGetDates($data["create_time"]);
        }
    }
    public function getImgsAttr($value, $data)
    {
        if(!empty($value)) {
            return explode(",", $value);
        }
    }
    public function dataAdd($data)
    {
        $data["create_time"] = time();
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page = 10)
    {
        $data = $this->where($dis)->order("top desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function coachDataList($dis, $alh, $page = 10)
    {
        $data = $this->alias("a")->join("massage_service_coach_list b", "a.coach_id = b.id", "left")->where($dis)->field(["a.*", $alh, "b.coach_name,b.work_img"])->order("a.top desc,a.create_time desc,distance asc,a.id desc")->paginate($page)->toArray();
        if(!empty($data["data"])) {
            foreach ($data["data"] as &$v) {
                $v["distance"] = distance_text($v["distance"]);
            }
        }
        return $data;
    }
    public function adminDataList($dis, $page = 10)
    {
        $data = $this->alias("a")->join("massage_service_coach_list b", "a.coach_id = b.id", "left")->where($dis)->field("a.*,b.coach_name,b.work_img")->order("a.top desc,a.create_time desc,a.id desc")->paginate($page)->toArray();
        return $data;
    }
    public function coachFollowDataList($dis, $alh, $page = 10)
    {
        $data = $this->alias("a")->join("massage_service_coach_list b", "a.coach_id = b.id", "left")->join("massage_dynamic_follow c", "a.coach_id = c.coach_id AND a.create_time >= c.create_time")->where($dis)->field(["a.*", $alh, "b.coach_name,b.work_img"])->group("a.id")->order("a.top desc,a.create_time desc,distance asc,a.id desc")->paginate($page)->toArray();
        if(!empty($data["data"])) {
            foreach ($data["data"] as &$v) {
                $v["distance"] = distance_text($v["distance"]);
            }
        }
        return $data;
    }
    public function getCommentNum($dis)
    {
        $num = $this->alias("a")->join("massage_dynamic_comment b", "a.id = b.dynamic_id")->where($dis)->where("b.status", "=", 2)->group("b.id")->count();
        return $num;
    }
    public function getThumbsNum($dis)
    {
        $num = $this->alias("a")->join("massage_dynamic_thumbs b", "a.id = b.dynamic_id")->where($dis)->where("b.status", "=", 1)->group("b.id")->count();
        return $num;
    }
}

?>